package Servlets;

import main.ServerGlobals;

import org.json.simple.JSONObject;

import protocol.HTTPRequest;
import protocol.HTTPResponse;
import protocol.Headers;

public class Logout extends Servlet {

	@Override
	public HTTPResponse process(HTTPRequest httpRequest,
			ServerGlobals serverGlobals) {
		if (!this.isCorrectMethod(httpRequest, Headers.GET)) {
			return new HTTPResponse(Headers.STATUS_405, Headers.HTTP_VERSION,
					new JSONObject(), "", false);
		}
		if (httpRequest.getfHTTPHttpRequestHeaders().getfCookies()
				.get(Headers.SESSIONID) != null) {
			serverGlobals.deleteSession((String) httpRequest
					.getfHTTPHttpRequestHeaders().getfCookies()
					.get(Headers.SESSIONID));
		}

		return new HTTPResponse(Headers.STATUS_200, Headers.HTTP_VERSION,
				new JSONObject(), WhatsAppConstatnts.LOGOUT_MESSAGE, true);
	}
}
